<template>
  <a-modal
    :title="title"
    :after-close="reset"
    @ok="submit"
  >
    <a-form
      ref="formRef"
      :model="form"
      :rules="rules"
      :label-col="{style: { width: '80px' }}"
    >
                                                        <a-form-item label="商品id" name="productId">
                    <a-input  v-model:value="form.productId" placeholder="商品id"></a-input>
                </a-form-item>
                                                <a-form-item label="分类id" name="cateId">
                    <a-input  v-model:value="form.cateId" placeholder="分类id"></a-input>
                </a-form-item>
                                                <a-form-item label="添加时间" name="addTime">
                    <a-input  v-model:value="form.addTime" placeholder="添加时间"></a-input>
                </a-form-item>
                        </a-form>
  </a-modal>
</template>

<script setup lang="ts">
import { storeproductcateAddup, storeproductcateinfo } from './api';
import { storeproductcate, type Istoreproductcate } from './entity';
import { validReg } from '@/utils/validate';

const props = withDefaults(defineProps<{
  data: Partial<Istoreproductcate>
}>(),{
})
const title = computed(() => props.data.id ? '编辑' : '新增')
const { formRef, submit, close } = useDialog({ validCallback: save })

let form = $ref(new storeproductcate())
watchEffect(() => {
  if (props.data.id) {
    storeproductcateinfo(props.data.id).then(res => {
      form.setProps(res)
    })
  }
})

const rules = {
        storeproductcateName: [validReg('required', '请输入用户名')]
}

onMounted(() => {
})
const emit = defineEmits(['change'])
function save() {
    storeproductcateAddup(form).then(() => {
    AntMessage.success('保存成功')
    close()
    emit('change')
  })
}

function reset() {
  form = new storeproductcate()
}
</script>

<style lang="less"></style>